package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.ACell;
import com.ruoyi.lock.service.IACellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小区管理Controller
 * 
 * @author arvin
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/lock/cell")
public class ACellController extends BaseController
{
    @Autowired
    private IACellService aCellService;

    /**
     * 查询小区管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:cell:list')")
    @GetMapping("/list")
    public TableDataInfo list(ACell aCell)
    {
        startPage();
        List<ACell> list = aCellService.selectACellList(aCell);
        return getDataTable(list);
    }

    /**
     * 查询小区管理列表 下拉使用
     */
    @PreAuthorize("@ss.hasPermi('lock:cell:list')")
    @GetMapping("/list2")
    public TableDataInfo list2(ACell aCell)
    {
        List<ACell> list = aCellService.selectACellList(aCell);
        return getDataTable(list);
    }

    /**
     * 导出小区管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:cell:export')")
    @Log(title = "小区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ACell aCell)
    {
        List<ACell> list = aCellService.selectACellList(aCell);
        ExcelUtil<ACell> util = new ExcelUtil<ACell>(ACell.class);
        util.exportExcel(response, list, "小区管理数据");
    }

    /**
     * 获取小区管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:cell:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aCellService.selectACellById(id));
    }

    /**
     * 新增小区管理
     */
    @PreAuthorize("@ss.hasPermi('lock:cell:add')")
    @Log(title = "小区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ACell aCell)
    {
        return toAjax(aCellService.insertACell(aCell));
    }

    /**
     * 修改小区管理
     */
    @PreAuthorize("@ss.hasPermi('lock:cell:edit')")
    @Log(title = "小区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ACell aCell)
    {
        return toAjax(aCellService.updateACell(aCell));
    }

    /**
     * 删除小区管理
     */
    @PreAuthorize("@ss.hasPermi('lock:cell:remove')")
    @Log(title = "小区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aCellService.deleteACellByIds(ids));
    }

    @Anonymous
    @GetMapping("/cellTree")
    public AjaxResult cellTree() {
        return success(aCellService.cellTree());
    }
}
